package com.song.cloud.controller;

import com.song.cloud.pojo.Book;
import com.song.cloud.service.BookService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2024/1/2
 * @Version 1.0
 **/
@RestController
@RequestMapping("/book")
public class BookController {

    @Value("${server.port}")
    private Integer port;
    @Resource
    private BookService bookService;

    @GetMapping("/")
    public List<Book> bookList(){
        System.out.println(this.port+"的生产者提供的数据。");
        return this.bookService.findAll();
    }


    @PutMapping("/")
    public boolean update(@RequestBody Book book){
         this.bookService.update(book);
         return true;
    }
    @PostMapping("/")
    public boolean add(@RequestBody Book book){
        this.bookService.save(book);
        return true;
    }

    @GetMapping("/{id}")
    public Book findOne(@PathVariable Integer id) {
        return this.bookService.findById(id);
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable  int id){
        this.bookService.delete(id);
        return true;
    }
}
